<template>
  <div>
    <!-- table -->
    <a-row>
      <a-col :span="24">
        <a-card>
          <a slot="extra">
            <a-button @click="save" :loading="loadingSave" type="link">{{ $t('fackerReport.bc') }}</a-button>
          </a>
          <a-tabs tabPosition="top" type="card">
            <a-tab-pane tab="{{ $t('fackerReport.sybb') }}" key="1">
              <a-row style="margin-bottom: 10px;" :gutter="16">
                <a-col :span="8">
                  <a-input v-model="fackerData.incomes.balance" addonBefore="{{ $t('fackerReport.kyye') }}"/>
                </a-col>
                <a-col :span="8">
                  <a-input v-model="fackerData.incomes.income.yesterday" addonBefore="{{ $t('fackerReport.zrsy') }}"/>
                </a-col>
                <a-col :span="8">
                  <a-input v-model="fackerData.incomes.income.today" addonBefore="{{ $t('fackerReport.jrsy') }}"/>
                </a-col>
              </a-row>
              <a-row style="margin-bottom: 10px;" :gutter="16">
                <a-col :span="8">
                  <a-input v-model="fackerData.incomes.income.week" addonBefore="{{ $t('fackerReport.bzsy') }}"/>
                </a-col>
                <a-col :span="8">
                  <a-input v-model="fackerData.incomes.income.month" addonBefore="{{ $t('fackerReport.bysy') }}"/>
                </a-col>
                <a-col :span="8">
                  <a-input v-model="fackerData.incomes.income.last_month" addonBefore="{{ $t('fackerReport.sysy') }}"/>
                </a-col>
              </a-row>
              <a-row style="margin-bottom: 10px;" :gutter="16">
                <a-col :span="8">
                  <a-input v-model="fackerData.incomes.freeze_money" addonBefore="{{ $t('fackerReport.djje') }}"/>
                </a-col>
                <a-col :span="8">
                  <a-input v-model="fackerData.incomes.used_cnt" addonBefore="{{ $t('fackerReport.jrqds') }}"/>
                </a-col>
                <a-col :span="8">
                  <a-input v-model="fackerData.incomes.remain_cnt" addonBefore="{{ $t('fackerReport.jrsyds') }}"/>
                </a-col>
              </a-row>
            </a-tab-pane>
            <a-tab-pane tab="{{ $t('fackerReport.tdbb') }}" key="2">
              <a-row style="margin-bottom: 10px;" :gutter="16">
                <a-col :span="8">
                  <a-input v-model="fackerData.team.balance" addonBefore="{{ $t('fackerReport.tdye') }}"/>
                </a-col>
                <a-col :span="8">
                  <a-input v-model="fackerData.team.water" addonBefore="{{ $t('fackerReport.tdls') }}"/>
                </a-col>
                <a-col :span="8">
                  <a-input v-model="fackerData.team.recharge" addonBefore="{{ $t('fackerReport.tdzcz') }}"/>
                </a-col>
              </a-row>
              <a-row style="margin-bottom: 10px;" :gutter="16">
                <a-col :span="8">
                  <a-input v-model="fackerData.team.withdraw" addonBefore="{{ $t('fackerReport.tdztx') }}"/>
                </a-col>
                <a-col :span="8">
                  <a-input v-model="fackerData.team.order" addonBefore="{{ $t('fackerReport.tdddyj') }}"/>
                </a-col>
                <a-col :span="8">
                  <a-input v-model="fackerData.team.first_cnt" addonBefore="{{ $t('fackerReport.scrs') }}"/>
                </a-col>
              </a-row>
              <a-row style="margin-bottom: 10px;" :gutter="16">
                <a-col :span="8">
                  <a-input v-model="fackerData.team.first_sub_cnt" addonBefore="{{ $t('fackerReport.ztrs') }}"/>
                </a-col>
                <a-col :span="8">
                  <a-input v-model="fackerData.team.cnt" addonBefore="{{ $t('fackerReport.tdrs') }}"/>
                </a-col>
                <a-col :span="8">
                  <a-input v-model="fackerData.team.new_cnt" addonBefore="{{ $t('fackerReport.xzrs') }}"/>
                </a-col>
              </a-row>
              <a-row style="margin-bottom: 10px;" :gutter="16">
                <a-col :span="8">
                  <a-input v-model="fackerData.team.recharge_cnt" addonBefore="{{ $t('fackerReport.czrs') }}"/>
                </a-col>
              </a-row>
            </a-tab-pane>
            <a-tab-pane tab="{{ $t('fackerReport.txbb') }}" key="3">
              <a-textarea v-model="fackerData.withdraw" placeholder="$t('fackerReport.yxytjl')($t('fackerReport.rq'),$t('fackerReport.je'))" :rows="10" />
            </a-tab-pane>
          </a-tabs>
        </a-card>
      </a-col>
    </a-row>
  </div>
</template>

<script>
import { mixin, mixinDevice } from '@/utils/mixin'
import { ACCESS_TOKEN } from '@/store/mutation-types'

export default {
  name: 'facker_report',
  mixins: [mixin, mixinDevice],
  components: {
  },
  data () {
    return {
      loadingSave: false,
      description: this.$t('fackerReport.sjlb'),
      loading: false,
      memberLoading: false,
      curr_id: '',
      // table
      columns: [
        {
          title: this.$t('fackerReport.lx'),
          dataIndex: 'belong',
          key: 'belong',
          scopedSlots: { customRender: 'username' }
        },
        {
          title: this.$t('fackerReport.xx'),
          dataIndex: 'info',
          key: 'info',
          scopedSlots: { customRender: 'info' }
        },
        {
          title: this.$t('fackerReport.cz'),
          key: 'action',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      data: [],
      total: 0,
      errors: [],
      curr_token: '',
      userList: [
      ],
      fackerData: {
        username: '',
        incomes: {
          balance: 0,
          income: {
            yesterday: 0,
            today: 0,
            week: 0,
            month: 0,
            last_month: 0
          },
          freeze_money: 0,
          used_cnt: 0,
          remain_cnt: 0
        },
        team: {
          balance: 0,
          water: 0,
          recharge: 0,
          withdraw: 0,
          order: 0,
          first_cnt: 0,
          first_sub_cnt: 0,
          cnt: 0,
          new_cnt: 0,
          recharge_cnt: 0
        },
        withdraw: ''

      }
    }
  },
  created () {
    this.getList()
  },
  methods: {
    getList () {
      this.$http.get('/facker_data/list').then(res => {
        this.userList = res
      }).catch(err => {
        this.$notification.error({
          message: this.$t('fackerReport.sb'),
          description: err.message
        })
      })
    },
    handleClickRead (row) {
      this.fackerData = {
        username: row.username,
        withdraw: row.withdraw,
        incomes: row.incomes,
        team: row.team
      }
    },
    save () {
      if (this.fackerData.username === '') {
        return
      }
      this.loadingSave = true
      this.$http.post('/facker_data/save', this.$qs.stringify({
        username: this.fackerData.username,
        incomes: JSON.stringify(this.fackerData.incomes),
        team: JSON.stringify(this.fackerData.team),
        withdraw: this.fackerData.withdraw
      })).then(res => {
        if (res.code === 0) {
          this.getList()
        } else {
          this.$notification.error({
            message: this.$t('fackerReport.sb'),
            description: res.msg
          })
        }
      }).catch(err => {
        this.$notification.error({
          message: this.$t('fackerReport.sb'),
          description: err.message
        })
      }).then(()=>{
        this.loadingSave = false
      })
    },
    remove (username) {
      this.$http.post('/facker_data/delete', this.$qs.stringify({
        username: username
      })).then(res => {
        if (res.code === 0) {
          this.getList()
        } else {
          this.$notification.error({
            message: this.$t('fackerReport.sb'),
            description: res.msg
          })
        }
      }).catch(err => {
        this.$notification.error({
          message: this.$t('fackerReport.sb'),
          description: err.message
        })
      })
    }
  }
}
</script>

<style lang="less" scoped>
  .card{
    margin-bottom: 24px;
  }
</style>
